package com.example.homework3;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

public class Multiplechoicedialogbox extends DialogFragment
{
    private Multiplechoicedialogbox.NotifyDialogListener listener;
    public  interface NotifyDialogListener
    {
        public void onDialogPositiveClicked(String gender);
    }

    public void SetLister(Multiplechoicedialogbox.NotifyDialogListener listener)
    {
        this.listener=listener;
    }
    private String[] genders=new String[]{"男","女"};

    public Dialog onCreateDialog(Bundle savedInstanceState)
    {
        AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
        builder.setTitle("请选择性别")
                .setMultiChoiceItems(genders, null, new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                        listener.onDialogPositiveClicked(genders[which]);
                    }
                })
                .setPositiveButton("确定", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        Toast.makeText(getActivity().getApplicationContext(),"你点击了确定",Toast.LENGTH_SHORT).show();
                    }
                })
                .setNeutralButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        Toast.makeText(getActivity().getApplicationContext(),"你点击了取消",Toast.LENGTH_SHORT).show();
                    }
                });
        return builder.create();
    }

}
